package vsqlbuilder;
import java.awt.Font;
import java.awt.MediaTracker;
import java.io.File;
import java.net.URL;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import javax.swing.ImageIcon;




public class Utils {

	private static final String IMAGES_PATH = "vsqlbuilder/resources/images/"; //fix it put relative not fixed
    private static final String REPLACE_PATTERN = "%";
	private static ResourceBundle resources;
	public static enum kindofJoin {EQUAL};
	public static final Font MINIFONT = new Font("Arial", Font.PLAIN, 9);
	public static final Font MINIFONTBOLD = new Font("Arial", Font.BOLD , 9);
	/**
	 * Including following operators: 	 * =, !=, <, >, <=, >=, IN, BETWEEN, LIKE,
	 * And logic connectors: AND, OR, NOT
	 * */
	public static enum typeofRestriction {EQUAL, NOT_EQUAL,LESS,MORE,LESS_EQUAL,MORE_EQUAL,BETWEEN,LIKE,NOT_LIKE,ILIKE,NOT_ILIKE,IN,NOT_IN,NOT_BETWEEN,IS_NULL,IS_NOT_NULL};
	public static enum typeofConnector {AND, OR};
	

	
	 public static ImageIcon getImageIcon(String fileName) {

			ImageIcon ii = null;
			URL resource = ClassLoader.getSystemResource(IMAGES_PATH + fileName);


			if (resource != null) {
			    ii = new ImageIcon(resource);
			}
			if ((ii == null) || (ii.getImageLoadStatus() != MediaTracker.COMPLETE)) {
			    RuntimeException exc = new RuntimeException(
				    "Image file not found: " + fileName);
			    throw exc;
			}
			return ii;
		    }

	    public static String getResource(String key, String value) {

	    	String resource = getResource(key);
	    	if (value.indexOf(File.separator) < 0) {
	    	    return resource.replaceFirst(REPLACE_PATTERN, value);
	    	}
	    	String safeReplacement = value.replaceAll("\\\\", "\\\\\\\\");
	    	safeReplacement = safeReplacement.replaceAll("\\$", "\\\\\\$");

	    	return resource.replaceFirst(REPLACE_PATTERN, safeReplacement);
	        }
	    
	    public static String getResource(String key) {

	    	String resource = null;
	    	try {
	    	    resource = resources.getString(key);
	    	} catch (MissingResourceException exc) {
	    		System.out.println(exc.getMessage()); //TODO [medium]: temporary fix, should be replace by a good exception manager
	    	}
	    	return resource;
	        }

	    
	    
	 
	
}
